#ifndef QTRENDWIDGET_H
#define QTRENDWIDGET_H

#include "../../libs/core/qabstractpagewidget.h"

#include <QWidget>
#include <QDateTime>
#include <QStringList>
#include <QProgressDialog>

namespace Ui {
class QTrendWidget;
}

class QMission;
class QTrendFileData;
struct tagTrendData;
struct tagTrendValue;

#define TREND_CONTROL_ADDRESS       0x0f31

class QTrendWidget;
class QCustomPlot;
class QProgressBarDialog;

class QTrendPluginWidget: public QAbstractPageWidget
{
    Q_OBJECT
public:
    QTrendPluginWidget(QWidget* parent=0);
protected:
    QTrendWidget    *m_widget;
private slots:
};

class QTrendWidget : public QWidget
{
    Q_OBJECT
    
public:
    explicit QTrendWidget(QWidget *parent = 0);
    ~QTrendWidget();
protected:
    void set_data(tagTrendData* data);
    void    set_button_color(QColor c,QPushButton* button);
protected slots:
    void mousePress();
    void mouseWheel();

    void    mission_success(QMission* ms);

    void    online();
    void    offline();

    void    trend_start();
    void    trend_end();
    void    trend_count(int count);
    void    trend_time_out();

    void    zoomin();
    void    zoomout();
    void    zoomin_x();
    void    zoomout_x();
    void    zoomin_y();
    void    zoomout_y();

    void    first();
    void    prev();
    void    next();
    void    last();
    void    remove();

    void    reset();

    void    save();
    void    open();

    void    trend_file_size_changed();

    void    save_as_picture();

    void    show_data();

private slots:
    void on_line_1_visible_clicked();
    void on_line_2_visible_clicked();
    void on_line_3_visible_clicked();
    void on_line_4_visible_clicked();

    void on_line_1_color_button_clicked();
    void on_line_2_color_button_clicked();
    void on_line_3_color_button_clicked();
    void on_line_4_color_button_clicked();
protected:
    void    update_zoom_enabled();
public slots:
    void    start();
    void    clear();
protected:
    friend class QTrendPluginWidget;
private:
    Ui::QTrendWidget *ui;
    QCustomPlot     *m_trend_widget;
    QMap<QString,tagTrendValue*>    m_name_to_value;
    QMap<int,tagTrendValue*>    m_index_to_value;
    tagTrendData    *m_current_data;
    QTrendFileData  *m_trend_file;
    QList<QMission*>    m_mission_list;
    QString         m_start_uuid;
    QProgressBarDialog  *m_progress_dialog;

    QAction*        m_first_action;
    QAction*        m_last_action;
    QAction*        m_next_action;
    QAction*        m_prev_action;
    QAction*        m_delete_action;

    QAction*        m_zoomin_action;
    QAction*        m_zoomout_action;
    QAction*        m_zoomin_x_action;
    QAction*        m_zoomout_x_action;
    QAction*        m_zoomin_y_action;
    QAction*        m_zoomout_y_action;
    QAction*        m_reset_action;
    QAction*        m_clear_action;

    QAction*        m_start_action;

    QAction*        m_save_action;
    QAction*        m_save_as_action;

    QAction*        m_show_data_atcion;

    QColor          m_color[4];
};

#endif // QTRENDWIDGET_H
